package hanxx.system.controller;

import hanxx.common.utils.AjaxResult;
import hanxx.security.domain.SysUser;
import hanxx.security.domain.SysUserLogin;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * @edit:韩鑫鑫
 * @Date: 2022/08/15/15:06
 * @Description:
 */
public class BaseController {

    /**
     * 获得登录者的sysUserLogin信 息
     * @return
     */
    public SysUserLogin getUserLogin(){
        SysUserLogin principal = (SysUserLogin) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        return principal;
    }

    /**
     * 获取登陆者的sysUser信息
     * @return
     */
    public SysUser getSysUser(){
        SysUserLogin principal = getUserLogin();
        return principal.getSysUser();
    }

    /**
     * 响应返回结果
     *
     * @param rows 影响行数
     * @return 操作结果
     */
    protected AjaxResult toAjax(int rows)
    {
        return rows > 0 ? AjaxResult.success() : AjaxResult.error();
    }
}
